using WooEngine.Common;

namespace WooEngine.Res
{
    public interface IResourcesUpdateProvider
    {
        void Initialize(string url, string plist, string md5, System.Action<bool, string> callback);
        void CheckForUpdates(object key, System.Action<object, long> callback);
        void StartDownload(object key, System.Action<object, float> percentComplete, System.Action<object> downloadComplete, System.Action<object, string> downloadFailed, int retry, int times);
    }

    public class UpdateManager : SingletonBehaviour<UpdateManager>
    {

        public IResourcesUpdateProvider Provider { get; private set; }

        public void Initialize(IResourcesUpdateProvider updater, string url, string plist, string md5 = null, System.Action<bool, string> callback = null)
        {
            Provider = updater;
            Provider.Initialize(url, plist, md5, callback);
        }


        public void CheckForUpdates(object key, System.Action<object, long> callback)
        {
            if (Provider != null)
                Provider.CheckForUpdates(key, callback);
        }

        public void StartDownload(object key, System.Action<object, float> percentComplete, System.Action<object> downloadComplete, System.Action<object, string> downloadFailed, int retry, int times = 0)
        {
            if (Provider != null)
                Provider.StartDownload(key, percentComplete, downloadComplete, downloadFailed, retry, times);
        }
    }
}